﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;

namespace HostApplication
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            try
            {

                // creation of a TCP-binary channel on port 12000
                TcpChannel channel = new TcpChannel(12000);
                // channel registration
                ChannelServices.RegisterChannel(channel, true); //secure channel
                //RemotingConfiguration.RegisterWellKnownServiceType(typeof(HostObject), "HostObject", WellKnownObjectMode.Singleton); // Singleton design pattern
                string exePath = Environment.GetCommandLineArgs()[0];
                RemotingConfiguration.Configure(System.IO.Path.GetDirectoryName(exePath) + "\\HostApplication.exe.config", false);

                Console.WriteLine("Server running");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error creating/registering the channel : " + e.ToString());
                Console.ReadLine();
            }
        }
    }
}
